package com.spr.validation;

import java.util.ArrayList;

import org.springframework.validation.Errors;
import org.springframework.stereotype.Component;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.spr.model.Schedule;
import com.spr.model.Student;


@Component
public class StudentValidator implements Validator{	
	
	@Override
	public boolean supports(Class<?> arg0) {
		return true;
	}

	@Override
	public void validate(Object target, Errors errors) {
		   
		if(target.getClass().equals(Student.class)){
		Student student = (Student) target;
           Integer studentId = null;
           studentId = student.getStudentID();
           
           
           
           ValidationUtils.rejectIfEmpty(errors, "firstName", "student.firstName.empty");
           ValidationUtils.rejectIfEmpty(errors, "lastName", "student.lastName.empty");
           ValidationUtils.rejectIfEmpty(errors, "email", "student.email.empty");

		}
		else{		
			Student schedule = (Student) target;
	           Integer scheduleID = null;
	           scheduleID = schedule.getScheduleID();
	           
	           
//	           
//	           ValidationUtils.rejectIfEmpty(errors, "fromMonday", "schedule.fromMonday.empty");
//	           ValidationUtils.rejectIfEmpty(errors, "toMonday", "schedule.toMonday.empty");
		}
           //if (studentId != null && studentId < 1)
             //      errors.rejectValue(STUDENT_ID, "student.Id.lessThanOne");

	}

}
